package com.ruoyi.web.controller.dict;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dict.domain.TDictFaultType;
import com.ruoyi.dict.service.ITDictFaultTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障类型Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/system/fault/type")
public class TDictFaultTypeController extends BaseController
{
    @Autowired
    private ITDictFaultTypeService tDictFaultTypeService;

    /**
     * 查询故障类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDictFaultType tDictFaultType)
    {
        startPage();
        List<TDictFaultType> list = tDictFaultTypeService.selectTDictFaultTypeList(tDictFaultType);
        return getDataTable(list);
    }

    /**
     * 导出故障类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "故障类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDictFaultType tDictFaultType)
    {
        List<TDictFaultType> list = tDictFaultTypeService.selectTDictFaultTypeList(tDictFaultType);
        ExcelUtil<TDictFaultType> util = new ExcelUtil<TDictFaultType>(TDictFaultType.class);
        util.exportExcel(response, list, "故障类型数据");
    }

    /**
     * 获取故障类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(tDictFaultTypeService.selectTDictFaultTypeByCode(code));
    }

    /**
     * 新增故障类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "故障类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDictFaultType tDictFaultType)
    {
        return toAjax(tDictFaultTypeService.insertTDictFaultType(tDictFaultType));
    }

    /**
     * 修改故障类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "故障类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDictFaultType tDictFaultType)
    {
        return toAjax(tDictFaultTypeService.updateTDictFaultType(tDictFaultType));
    }

    /**
     * 删除故障类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "故障类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(tDictFaultTypeService.deleteTDictFaultTypeByCodes(codes));
    }
}
